package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserOrderComment;
import com.happy.cat.project.system.service.IUserOrderCommentService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户订单评论Controller
 *
 * @author verne
 * @date 2020-08-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userOrderComment" )
@Api("用户订单评论 API")
public class UserOrderCommentController extends BaseController {

    private final IUserOrderCommentService iUserOrderCommentService;

    /**
     * 查询用户订单评论列表
     */
    @ApiOperation(value = "查询用户订单评论列表",notes = "查询用户订单评论列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserOrderComment userOrderComment)
    {
        startPage();
        LambdaQueryWrapper<UserOrderComment> lqw = new LambdaQueryWrapper<UserOrderComment>();
        if (StringUtils.isNotBlank(userOrderComment.getOrderCode())){
            lqw.eq(UserOrderComment::getOrderCode ,userOrderComment.getOrderCode());
        }
        if (userOrderComment.getUserId() != null){
            lqw.eq(UserOrderComment::getUserId ,userOrderComment.getUserId());
        }
        if (userOrderComment.getScore() != null){
            lqw.eq(UserOrderComment::getScore ,userOrderComment.getScore());
        }
        if (StringUtils.isNotBlank(userOrderComment.getCategory())){
            lqw.eq(UserOrderComment::getCategory ,userOrderComment.getCategory());
        }
        if (StringUtils.isNotBlank(userOrderComment.getContent())){
            lqw.eq(UserOrderComment::getContent ,userOrderComment.getContent());
        }
        List<UserOrderComment> list = iUserOrderCommentService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户订单评论列表
     */
    @ApiOperation(value = "导出用户订单评论列表",notes = "导出用户订单评论列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:export')" )
    @Log(title = "用户订单评论" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserOrderComment userOrderComment) {
        LambdaQueryWrapper<UserOrderComment> lqw = new LambdaQueryWrapper<UserOrderComment>(userOrderComment);
        List<UserOrderComment> list = iUserOrderCommentService.list(lqw);
        ExcelUtil<UserOrderComment> util = new ExcelUtil<UserOrderComment>(UserOrderComment. class);
        return util.exportExcel(list, "userOrderComment" );
    }

    /**
     * 获取用户订单评论详细信息
     */
    @ApiOperation(value = "获取用户订单评论详细信息",notes = "获取用户订单评论详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserOrderCommentService.getById(id));
    }

    /**
     * 新增用户订单评论
     */
    @ApiOperation(value = "新增用户订单评论",notes = "新增用户订单评论",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:add')" )
    @Log(title = "用户订单评论" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOrderComment userOrderComment) {
        return toAjax(iUserOrderCommentService.save(userOrderComment) ? 1 : 0);
    }

    /**
     * 修改用户订单评论
     */
    @ApiOperation(value = "修改用户订单评论",notes = "修改用户订单评论",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:edit')" )
    @Log(title = "用户订单评论" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOrderComment userOrderComment) {
        return toAjax(iUserOrderCommentService.updateById(userOrderComment) ? 1 : 0);
    }

    /**
     * 删除用户订单评论
     */
    @ApiOperation(value = "删除用户订单评论",notes = "删除用户订单评论",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderComment:remove')" )
    @Log(title = "用户订单评论" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserOrderCommentService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
